<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
	protected function _initDoctrine() {
		require dirname ( __FILE__ ) . '/../library/Doctrine.php';
		spl_autoload_register ( array (
				'Doctrine',
				'autoload' 
		) );
		spl_autoload_register ( array (
				'Doctrine',
				'modelsAutoload' 
		) );
		$config = new Zend_Config_Ini ( APPLICATION_PATH . '/configs/doctrine.ini', 'doctrine' );
		
		$Manager = Doctrine_Manager::getInstance ();
		
		// config for my mysql connection
		// if you want to use another one --> let's change this pattern
		/*
		 * my database driver mysql://username:password@host/dbname
		 */
		$dsn = $config->adapter . '://' . $config->username . ':' . $config->password . '@' . $config->host . '/' . $config->dbname . '?charset=utf8';
		
		// set as default connnection name
		$conn = Doctrine_Manager::connection ( $dsn, 'doctrine' );
		
		// telling Doctrine where our models are located
		Doctrine::loadModels ( APPLICATION_PATH . '/models/generated' );
		Doctrine::loadModels ( APPLICATION_PATH . '/models' );
		// print_r(APPLICATION_PATH . '/models');die();
		// set the default primary key to be named 'id', integer, 4 bytes
		$Manager->setAttribute ( Doctrine_Core::ATTR_DEFAULT_IDENTIFIER_OPTIONS, array (
				'name' => 'id',
				'type' => 'integer',
				'length' => 4 
		) );
		
		// We want UTF8
		$Manager->setCollate ( 'utf8_unicode_ci' );
		$Manager->setCharset ( 'utf8' ); // print_r(APPLICATION_PATH .
			                                 // '/models');die();
	}
	protected function _initAutoload() {
		$Settings = Systems::getAllWithoutPager ();
		$Systems = array ();
		foreach ( $Settings as $key => $value ) {
			if ($value->status == 1) {
				$Systems [$value->name] = $value;
			}
		}
		Zend_Registry::set ( 'Setting', $Systems );
		if (isset ( $_SESSION ['IS_MOBILE'] ) && isset ( $_GET ['IS_MOBILE'] )) {
			if ($_GET ['IS_MOBILE'] == 0)
				$_SESSION ['Q_MOBILE'] = 1;
			else
				$_SESSION ['Q_MOBILE'] = 0;
		}
	}
	protected function _initRoutes() {
		$front = Zend_Controller_Front::getInstance ();
		$router = $front->getRouter ();
		$router_name = 'default';
		$router_path = APPLICATION_PATH . '/modules/default/configs/routes.xml';
		$routes = new Zend_Config_Xml ( $router_path, null );
		$router->addConfig ( $routes );
	}
}

